<%-- 
    Document   : Articulo
    Created on : 27/06/2013, 01:12:53 PM
    Author     : SHAI
--%>

<%@page import="bean.Articulo"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page language='java' 
        contentType="text/html" 
        info="Pagina Principal" 
        errorPage='index.jsp' 
        import="java.util.ArrayList;"
        %>
<jsp:useBean id="beanUsr" class="bean.Usuario" scope="session" />
<jsp:useBean id="gArticulo" class="bean.gestionArticulos" scope="session" />             
<jsp:useBean id="Articulo" class="bean.Articulo" scope="session" />    
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="css/style.css">
        <link rel="stylesheet" type="text/css" href="css/styleArticulos.css">
        <script type="text/javascript" src="js/jquery-latest.js"></script> 
        <script type="text/javascript" src="js/__jquery.tablesorter.min.js"></script> 
        <title>Gestion de Articulos</title>
        <script>
            $(function() {		
                $("#myTable").tablesorter({sortList:[[0,0],[2,1]], widgets: ['zebra']});
            });	
        </script>
    </head>
    <body>
        <jsp:include page="header.jsp"/>
        <div id="main">
            <div id="control">
                <div id="controli">

                    <%
                        if (beanUsr.isActive()&&beanUsr.getRol()>0) {
                            out.print("<a href=\"articulo.jsp?articulo=nuevo\" >Nuevo Articulo</a>");
                        }
                    %>
                </div>
                <div id="controld">
                    <form id="Login" action="listaArticulos.jsp" method="post" >
                        <div class="form_settings">
                            <% String value = request.getParameter("articulo");%>
                            <p><span>Buscar:</span><input class="contact" type="text" name="articulo" value=<%out.print("\"" + value + "\"");%> /></p>
                        </div>
                    </form>
                </div>
            </div>
            <div id="contenidolista">
                <h1>Listado de Articulos Encontrados</h1>
                <%//gestionArticulos gArticulos = new gestionArticulos();
                    ArrayList<Articulo> lista = gArticulo.getArticulos(value);//gArticulos.getArticulos(value);
                    if (!lista.isEmpty()) {
                %>
                <table id="myTable" class="tablesorter" border="0" cellpadding="0" cellspacing="1" >
                    <thead>
                        <tr>
                            <th class="header headerSortDown">Titulo</th>
                            <th class="header">Revision</th>
                            <th class="header">Autor</th>
                            <th class="header headerSortUp">Fecha</th>
                            <th class="header">Puntuacion</th>
                            <th class="header">Votos</th>
                            <%
                                if (beanUsr.isActive()) {
                                    out.print("<th class=\"header\">Opciones</th>");
                                }
                            %>
                        </tr>
                    </thead>
                    <tbody>
                        <% for (int i = 0; i < lista.size(); i++) {
                                if (!(i % 2 != 0)) {
                                    out.print("<tr class=\"odd\">");
                                } else {
                                    out.print("<tr class=\"even\">");
                                }
                                out.print("<td>" + lista.get(i).getTitulo() + "</td>");
                                out.print("<td>" + lista.get(i).getRevision() + "</td>");
                                out.print("<td>" + lista.get(i).getAutor() + "</td>");
                                out.print("<td>" + lista.get(i).getFecha() + "</td>");
                                out.print("<td>" + lista.get(i).getPunteo() + "</td>");
                                out.print("<td>" + lista.get(i).getCantidadVotos() + "</td>");
                                if (beanUsr.isActive()) {
                                    if (beanUsr.getRol() == 0) {
                                        out.print("<td><a href=\"leerArticulo.jsp?articulo=" + lista.get(i).getId() + "\">Leer</a></td>");
                                    } else {
                                        out.print("<td><a href=\"leerArticulo.jsp?articulo=" + lista.get(i).getId() + "\">Leer</a>");
                                        out.print("&nbsp;&nbsp;<a href=\"articulo.jsp?articulo=" + lista.get(i).getId() + "\">Modificar</a></td>");
                                    }
                                }
                                out.print("</tr>");
                            }
                        %>
                    </tbody>
                </table>
                <%} else {
                        out.print("<p id=\"barraBuscar\">No se encontraron resultados.</p>");
                    }
                %>
            </div>
        </div>
    </body>
</html>
